import { ref, watch, watchEffect } from "vue";
import axios from "axios";

function UseList() {
  const select = ref("ldh");
  const datalist = ref([]);

  // watch(
  //   select,
  //   async (value) => {
  //     const res = await axios.get(`http://localhost:3000/news?author=${value}`);
  //     datalist.value = res.data;
  //     console.log("==>", res.data);
  //   },
  //   { immediate: true }
  // );

  watchEffect(async () => {
    const res = await axios.get(
      `http://localhost:3000/news?author=${select.value}`
    );
    datalist.value = res.data;
    console.log("==>", res.data);
  });

  return {
    select,
    datalist,
  };
}

export default UseList;
